#ifndef __MAILBOX_H__
#define __MAILBOX_H__

#include "unione_lite.h"

#if defined(__cplusplus)
extern "C" {
#endif


#define MAILBOX_0        					0
#define MAILBOX_1        					1

#define MAILBOX_616							MAILBOX_1
#define	MAILBOX_INT_NUMBER					61
#define MAILBOX_PA_BASE                     MAILBOX_0_PA_BASE

#define MAILBOX_WRDATA(x)                  	(MAILBOX_PA_BASE + 0x100000 * (x) + 0x00)
#define MAILBOX_RDDATA(x)                   (MAILBOX_PA_BASE + 0x100000 * (x) + 0x08)
#define MAILBOX_STATUS(x)                   (MAILBOX_PA_BASE + 0x100000 * (x) + 0x10)
#define MAILBOX_ERR_STATUS(x)           	(MAILBOX_PA_BASE + 0x100000 * (x) + 0x14)
#define MAILBOX_TX_THRESHOLD(x)       		(MAILBOX_PA_BASE + 0x100000 * (x) + 0x18)
#define MAILBOX_RX_THRESHOLD(x)       		(MAILBOX_PA_BASE + 0x100000 * (x) + 0x1C)
#define MAILBOX_INT_STATUS(x)            	(MAILBOX_PA_BASE + 0x100000 * (x) + 0x20)
#define MAILBOX_INT_ENABLE(x)            	(MAILBOX_PA_BASE + 0x100000 * (x) + 0x24)
#define MAILBOX_INT_PENDING(x)          	(MAILBOX_PA_BASE + 0x100000 * (x) + 0x28)
#define MAILBOX_CTRL(x)                    	(MAILBOX_PA_BASE + 0x100000 * (x) + 0x2C)
#define MAILBOX_SEMA(x)                     (MAILBOX_PA_BASE + 0x100000 * (x) + 0x30)


#define SEMA_LOCK_CLR_BIT               	0x1
#define SEMA_LOCK_STATUS_BIT        		0x2
#define SEMA_LOCK_REQ_BIT              		0x4

#define IPC_MSG_MAX_DATA_SIZE  				5

typedef struct mailbox_message_t{    
	unsigned int sequenceId;    
	unsigned int taskId;    
	unsigned int size;    
	unsigned int data[IPC_MSG_MAX_DATA_SIZE];	
}mailbox_message;

typedef enum mailbox_lock_t{
	MAILBOX_LOCK0 = 0,
	MAILBOX_LOCK1
}mailbox_lock;


extern int mailbox_init(void (*mailbox_isr)(void *args), int rx_threshold, int tx_threshold, void *args);
extern int mailbox_sema_lock(mailbox_lock lock);
extern void mailbox_sema_unlock(mailbox_lock lock);
extern int mailbox_sema_is_lock(mailbox_lock lock);
extern int mailbox_send_msg(mailbox_message *message);

#if defined(__cplusplus)
}  /* extern "C" */
#endif

#endif /*__MAILBOX_H__*/
